﻿using System;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.UI;

namespace YuYuKiCms.Internet.Controllers
{
    [OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
    public class ValidationController : Controller
    {
        //private YuyukiModel _db;

        protected override void Initialize(RequestContext requestContext)
        {
            base.Initialize(requestContext);

            //if (null != Session[ContextModule.ContextKey])
            //    _db = Session[ContextModule.ContextKey] as YuyukiModel;
            //else
            //{
            //    throw new NoSuchObjectException("Cannot find YuyukiModel object", null);
            //}
        }

        public JsonResult IsEmailAvailable(string email)
        {
            //return Json(
            //    !_db.UserAccounts.Any(a => a.Email.Equals(email, StringComparison.OrdinalIgnoreCase)),
            //    JsonRequestBehavior.AllowGet);
            return Json(true,
                JsonRequestBehavior.AllowGet);
        }

        public JsonResult IsUrlTitleUniq(string urlTitle)
        {
            if (urlTitle.Equals(Session["page_url"] as string, StringComparison.OrdinalIgnoreCase))
            {
                // check if != than default (for create it's empty, for update it's the current value)
                // update
                // Session["page_url"] = p.UrlTitle;
                return Json(true, JsonRequestBehavior.AllowGet);
            }

            // Create
            return Json(true,
                JsonRequestBehavior.AllowGet);
            //return Json(!_db.PageMenus.Any(a => a.UrlTitle.Equals(urlTitle, StringComparison.OrdinalIgnoreCase)),
            //    JsonRequestBehavior.AllowGet);
        }
    }
}